package com.gxa.service.shezhiservice.Impl;

import com.gxa.common.R;
import com.gxa.mapper.shezhimapper.ShangPinType46Mapper;
import com.gxa.pojo.ShangPinType;
import com.gxa.pojo.ShangPinType;
import com.gxa.service.shezhiservice.ShangPinType46Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ShangPinType46ServiceImpl implements ShangPinType46Service {
    @Autowired
    private ShangPinType46Mapper shangPinType46Mapper;
    @Override
    public R selectAllShangPinTypeForPage(int page, int size) {
        R r = new R();
        int index = (page - 1)*size;
        List<ShangPinType> shangPinTypes = shangPinType46Mapper.selectAllShangPinTypeForPage(index ,size );
        if (shangPinTypes != null){
            r.setCode(200);
            r.setMsg("查询成功！");
            r.setData(shangPinTypes);
        }
        return r;
    }

    @Override
    public R selectShangPinTypeByType(int page, int size, String shangPinType) {
        R r = new R();
        int index = (page - 1)*size;
        List<ShangPinType> shangPinTypes = shangPinType46Mapper.selectShangPinTypeByType(index,size,shangPinType);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(shangPinTypes);
        return r;
    }

    @Override
    public R insertShangPinType(ShangPinType shangPin) {
        R r = new R();
        int res =  shangPinType46Mapper.insertShangPinType(shangPin);
        r.setCode(500);
        r.setMsg("新增失败");
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("新增成功");
        }
        return r;
    }

    @Override
    public R updateShangPinTypeById(ShangPinType keHu) {
        R r = new R();
        int res =  shangPinType46Mapper.updateShangPinTypeById(keHu);
        r.setCode(500);
        r.setMsg("更新失败");
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("更新成功");
        }
        return r;
    }

    @Override
    public R deleteShangPinTypeById(int id) {
        R r = new R();
        int res = shangPinType46Mapper.deleteShangPinTypeById(id);
        r.setCode(500);
        r.setMsg("删除失败");
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("删除成功");
        }
        return r;
    }
}
